package gamesys.games.particlesystem.effects
{
	import gamesys.games.particlesystem.core.ParticleData;
	import gamesys.games.particlesystem.utils.GeomUtils;
	import gamesys.games.particlesystem.utils.Range;

	/**
	 * @author robertthurston
	 */
	public class VelocityEffect implements IEffect
	{
		private var speed : Range;
		private var direction : Range;

		public function VelocityEffect(speed : Range, direction : Range)
		{
			this.speed = speed;
			this.direction = new Range(GeomUtils.degreesToRadions(direction.min), GeomUtils.degreesToRadions(direction.max));
		}

		public function reset(particleData : ParticleData) : void
		{
			var newSpeed : Number = speed.range;

			particleData.direction = direction.range;

			particleData.xSpeed += newSpeed * Math.sin(particleData.direction);
			particleData.ySpeed += newSpeed * -Math.cos(particleData.direction);
		}

		public function update(particleData : ParticleData) : void
		{
			particleData.x += particleData.xSpeed;
			particleData.y += particleData.ySpeed;
		}
	}
}
